package com.example.usercenter.exception;


import com.example.usercenter.common.BaseResponse;
import com.example.usercenter.common.ErrorCode;
import com.example.usercenter.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j

public class GlobalExceptionHandler {

    @ExceptionHandler(BussinessException.class)

    public BaseResponse  bussinessExceptionHandler(BussinessException e){

        log.error("bussinessExceptionHandler",e.getMessage(),e);

        return ResultUtils.error(e.getCode(),e.getMessage(),e.getDescription());
    }



    @ExceptionHandler(RuntimeException.class)

    public BaseResponse  runtimeExceptionHandler(BussinessException e){


        log.error("runtimeExceptionHandler",e);

       return ResultUtils.error(ErrorCode.SYSTEM_ERROR.getCode(),e.getMessage(),"");


    }



}
